﻿using System;
using Rhizome.Contract;

namespace Rhizome.Model
{
    public class CustomCriterion<TPlant> : CriterionBase<TPlant>
    {
        public event EventHandler<CriterionEventArgs<TPlant>> Calculate;

        public override bool Test()
        {
            var handler = Calculate;
            if (handler == null) throw new ValidationException("Event Calculate not set");

            var args = new CriterionEventArgs<TPlant>(Plant);
            handler(this, args);
            return args.IsTrue;
        }
    }

    public sealed class CriterionEventArgs<TPlant> : EventArgs
    {
        public CriterionEventArgs(TPlant plant)
        {
            Plant = plant;
        }

        public object Plant { get; private set; }

        public bool IsTrue { internal get; set; }
    }

    public sealed class CustomCriterion : CustomCriterion<object>
    {
    }
}